<%--
  Created by IntelliJ IDEA.
  User: LS
  Date: 2019/2/25
  Time: 11:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>登录</title>
		<link rel="stylesheet" href="../../resources/layui/css/layui.css" />
		<link rel="stylesheet" href="../../resources/css/style.css" />
		<script type="text/javascript" src="../../resources/js/jquery-1.11.1.min.js"></script>
		<script type="text/javascript" src="../../resources/layui/layui.all.js"></script>
	</head>

	<body>

		<div class="login-main layui-anim layui-anim-up">
			<header class="layui-elip">用户登录</header>
			<form class="layui-form" method="post">
				<div class="layui-input-inline">
					<input type="text" name="users.userName" id="userName" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-input-inline">
					<input type="password" name="users.userPwd" id="userPwd" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-input-inline login-btn">
					<button type="submit" class="layui-btn" lay-submit="" lay-filter="reLogin">登录</button>
				</div>
				<hr/>
				<p>
					<a href="javascript:(0)" class="fl">立即注册</a>
					<a href="javascript:;" class="fr">忘记密码？</a>
				</p>
			</form>
		</div>
		<script>
			$(document).ready(function(){
				$("#userName").focus();
			});
		</script>
		<script type="text/javascript">
			$('.fl').on('click', function() {
				parent.layer.closeAll();
				parent.layer.open({
					type: 2,
					title: '注册/登陆',
					shadeClose: true, //点击遮罩关闭层
					area: ['420px', '430px'],
					content: '/pages/relogin/register.jsp'
				});
			});
		</script>
		<script>
			layui.use("form", function() {
				var form = layui.form;
				form.on('submit(reLogin)', function(data) {
					var loading = layer.msg('请稍后....', {
						icon: 16,
						shade: 0.01
					});
					var userData = {
						"users.userName": $("#userName").val(),
						"users.userPwd": $("#userPwd").val()
					};
					var url = '/users/verUser.action';
					$.ajax({
						type: "post",
						url: url,
						data: userData,
						dataType: 'json',
						success: function(data) {
							if(data.result == true) {
								layer.msg('登录成功', {
									icon: 1, //提示的样式
									time: 1000, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
									end: function() {
										window.parent.location.reload();
										parent.layer.close(index);
									}
								});
							} else if(data.result == false) {
								layer.msg('密码或用户名错误', {
									icon: 2, //提示的样式
									time: 1000, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
								});
							}
						},
						error: function() {
							layer.msg("错误", {
								icon: 2,
							});
						},
						done: function() {
							layer.close(loading);
						}
					});
					return false;
				});
			});
		</script>
	</body>

</html>